/* Basic editor styles */
.tiptap {
  &:first-child {
    margin-top: 0;
  }

  /* List styles */
  ul,
  ol {
    padding: 0 1rem;
    margin: 1.25rem 1rem 1.25rem 0.4rem;
    
    li p {
      margin-top: 0.25em;
      margin-bottom: 0.25em;
    }
  }

  /* Heading styles */
  h1, h2, h3, h4, h5, h6 {
    line-height: 1.1;
    margin-top: 2.5rem;
    text-wrap: pretty;
  }

  h1, h2 {
    margin-top: 3.5rem;
    margin-bottom: 1.5rem;
  }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.1rem; }
  h4, h5, h6 { font-size: 1rem; }

  /* Code and preformatted text styles */
  code {
    background-color: var(--purple-light);
    border-radius: 0.4rem;
    color: var(--black);
    font-size: 0.85rem;
    padding: 0.25em 0.3em;
  }

  pre {
    background: var(--black);
    border-radius: 0.5rem;
    color: var(--white);
    font-family: 'JetBrainsMono', monospace;
    margin: 1.5rem 0;
    padding: 0.75rem 1rem;
    
    code {
      background: none;
      color: inherit;
      font-size: 0.8rem;
      padding: 0;
    }
  }

  blockquote {
    border-left: 3px solid var(--gray-3);
    margin: 1.5rem 0;
    padding-left: 1rem;
  }

  hr {
    border: none;
    border-top: 1px solid var(--gray-2);
    margin: 2rem 0;
  }

  /* Placeholder */
  .is-empty::before {
    color: var(--gray-4);
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
  }

  /* Image styling */
  img {
    display: block;
    height: auto;
    margin: 1.5rem 0;
    max-width: 100%;
    
    &.ProseMirror-selectednode {
      outline: 3px solid var(--purple);
    }
  }

  p {
    word-break: break-all;
  }

  /* Collaboration cursors */
  .collaboration-cursor__caret {
    border-left: 1px solid #0d0d0d;
    border-right: 1px solid #0d0d0d;
    margin-left: -1px;
    margin-right: -1px;
    pointer-events: none;
    position: relative;
    word-break: normal;
  }

  .collaboration-cursor__label {
    border-radius: 3px 3px 3px 0;
    color: #0d0d0d;
    font-size: 12px;
    font-style: normal;
    font-weight: 600;
    left: -1px;
    line-height: normal;
    padding: 0.1rem 0.3rem;
    position: absolute;
    top: -1.4em;
    user-select: none;
    white-space: nowrap;
  }

  /* Thread mark */
  .tiptap-thread, 
  .tiptap-thread * {
    transition: all 0.2s cubic-bezier(0.65,0.05,0.36,1);
  }

  .tiptap-thread[data-type="block"] {
    &:first-child {
      margin-top: 0;
    }

    > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
      outline-width: 2px;
      outline-color: transparent;
      outline-style: dashed;
    }
  }
}

/* Comments & Threads */
body { 
  overflow: hidden;
  
  .main {
    height: 100vh;
    overflow: auto;
  }

  .sidebar {
    width: 20rem;

    @media (max-width: 540px) {
      padding-bottom: 0;
      width: 100%;
    }
  }
}

.threads-group {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0 -1rem;
  overflow: auto;
  padding: 0 1rem;

  @media (max-width: 540px) {
    margin: 0 -1.5rem;
    max-height: 40vh;
    padding: 0 1.5rem 1.5rem;
    width: calc(100% + 3rem);
  }

  .thread {
    border-radius: 0.5rem;
    box-shadow: 0px 0px 0px 1px var(--gray-3) inset;
    display: flex;
    flex-direction: column;
    transition: all 0.2s cubic-bezier(0.65,0.05,0.36,1);

    &.is-active,
    &:hover {
      box-shadow: 0px 0px 0px 1px var(--gray-4) inset;
    }

    &.is-open {
      box-shadow: 0px 0px 0px 1px var(--purple) inset;
    }

    /* Thread header */
    .header-group {
      border-bottom: 1px solid var(--gray-3);
      padding: 0.375rem 0.5rem;

      button {
        background-color: unset;

        &:hover {
          background-color: var(--gray-2);
        }
      }
    }

    /* Hint */
    .hint {
      align-items: center;
      background-color: var(--yellow-light);
      border: 1px solid var(--gray-2);
      border-radius: 0.5rem;
      display: flex;
      flex-direction: row;
      font-size: 0.75rem;
      gap: 0.5rem;
      line-height: 1.15;
      min-height: 1.75rem;
      padding: 0.25rem 0.5rem;
      margin: 0.8rem 0.8rem 0;
    }

    /* Closed thread styles */
    &:not(.is-open) {
      .comments-group {
        .comment {
          &:not(:last-child) {
            padding-bottom: 0;
          }

          .comment-content {
            p {
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              align-self: stretch;
              display: -webkit-box;
            }
  
            .button-group {
              display: none;
            }
  
            label {
              display: inherit;
            }
          }
        }

        .comments-count {
          margin-top: 0.2rem;
        }
      }
    }

    /* Comments */
    .comments-group {
      display: flex;
      flex-direction: column;
      padding: 0.8rem;

      .comment {
        display: flex;
        flex-direction: column;
        gap: 0.125rem;

        &.deleted {
          opacity: .5;
        }
    
        &:not(:first-child) {
          border-top: 1px solid var(--gray-3);
          padding-top: 0.75rem;
        }

        &:not(:last-child) {
          padding-bottom: 0.75rem;
        }
  
        .comment-edit {
          padding: unset;
        }

        .comment-content {
          display: flex;
          flex-direction: column;
          gap: 0.625rem;
        }
      }
    }
  }

  /* Basic styling */
  button {
    font-size: 0.75rem;
    padding: 0.25rem 0.375rem;
    border-radius: 0.375rem;
  }

  .button-group {
    gap: 0.125rem;
  }

  label {
    color: var(--gray-5);
    font-size: 0.75rem;
    font-weight: 400;
  }

  p {
    font-size: 0.75rem;
    line-height: 1.4;
    margin: 0;
    overflow: hidden;
  }

  .label-group {
    column-gap: 0.25rem;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;

    label:not(:first-child)::before {
      content: "·";
      padding-right: 0.25rem;
    }

    label:first-of-type {
      font-weight: 700;
      color: var(--black);
    }
  }

  /* Reply input styling */
  .reply-group, 
  .comment-edit {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.2rem 0.8rem 0.8rem;

    textarea {
      height: 4.5rem;
      resize: none; 
      padding: 0.375rem 0.625rem;
      line-height: 1.3;
      width: 100%;

      &:focus,
      &:focus-visible {
        border-color: var(--black);
      }
    }

    .flex-row {
      column-gap: 0.5rem;
      row-gap: 0.25rem;
    }
  }

  .reply-group {
    &:not(:has(textarea:focus)) {
      .flex-row {
        display: none;
      }
    }

    textarea:placeholder-shown:not(:focus) {
      height: 2rem;
    }

    textarea:not(:placeholder-shown) {
      height: 4.5rem;
    }

    &:has(textarea:not(:placeholder-shown)) {
      .flex-row {
        display: flex;
      }
    }
  }
}

/* Structure */
.col-group {
  display: flex;
  flex-direction: row;

  @media (max-width: 540px) {
    flex-direction: column-reverse;
  }
}

.main {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.sidebar {
  border-left: 1px solid var(--gray-3);
  flex-grow: 0;
  flex-shrink: 0;
  padding: 1rem;
  position: sticky;
  height: 100vh;
  top: 0;
  width: 20rem;

  @media (max-width: 540px) {
    border-bottom: 1px solid var(--gray-3);
    border-left: unset;
    width: 100%;
    height: auto;
    position: unset;
    padding: 1.5rem;
  }
}

.sidebar-options {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 1rem;
  position: sticky;
  top: 1rem;
}

.option-group {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  width: 100%;

  form {
    width: 100%;

    input {
      width: 100%;
    }
  }
}

/* View mode specific styles */
[data-viewmode="open"] .tiptap {
  .tiptap-thread[data-status-all="open"] {
    &[data-type="block"] {
      > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
        background-color: var(--yellow);
        outline-color: var(--yellow);
      }
  
      &:hover,
      &[data-state="selected"],
      &[data-state="hovered"] {
        > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
          background-color: var(--yellow-contrast);
          outline-color: var(--yellow-contrast);
        }
      }
    }

    &[data-type="inline"] {
      border-bottom: 2px dashed var(--yellow-contrast);

      &:hover,
      &[data-state="selected"],
      &[data-state="hovered"] {
        background-color: var(--yellow);
      }
    }
  }
}

[data-viewmode="resolved"] .tiptap {
  .tiptap-thread[data-status="closed"] {
    &[data-type="block"] {
      > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
        background-color: var(--yellow);
        outline-color: var(--yellow);
      }
  
      &:hover,
      &[data-state="selected"],
      &[data-state="hovered"] {
        > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
          background-color: var(--yellow-contrast);
          outline-color: var(--yellow-contrast);
        }
      }
    }

    &[data-type="inline"] {
      border-bottom: 2px dashed var(--yellow-contrast);

      &:hover,
      &[data-state="selected"],
      &[data-state="hovered"] {
        background-color: var(--yellow);
      }
    }
  }
}

/* NOTE: The original commented block is preserved as-is below */
/* [data-viewmode="open"] .tiptap .tiptap-thread:not([data-status="closed"]),
[data-viewmode="resolved"] .tiptap .tiptap-thread:not([data-status="open"]) {
  &[data-type="block"] {
    > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
      background-color: var(--yellow);
      outline-color: var(--yellow);
    }

    &:hover,
    &[data-state="selected"],
    &[data-state="hovered"] {
      > :not(p, h1, h2, h3, h4, h5, h6, ul, li) {
        background-color: var(--yellow-contrast);
        outline-color: var(--yellow-contrast);
      }
    }
  }

  &[data-type="inline"] {
    border-bottom: 2px dashed var(--yellow-contrast);

    &:hover,
    &[data-state="selected"],
    &[data-state="hovered"] {
      background-color: var(--yellow);
    }
  }
} */